package pri.black.dogview.util;

import java.time.LocalDate;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class HolidayUtils {

    class Holiday{
        private String name;
        private LocalDate start;
        private LocalDate end;

        public Holiday(String name, LocalDate start, LocalDate end) {
            this.name = name;
            this.start = start;
            this.end = end;
        }
    }

    List<Holiday> holidays = new LinkedList<>();
    List<LocalDate> workday = new LinkedList<>();
    public HolidayUtils(){
        add("元旦", 2025, 1, 1,2025,1,1);
        add("春节", 2025, 1, 28,2025,2,4);
        add("清明", 2025, 4, 4,2025,4,6);
        add("劳动", 2025, 5, 1,2025,5,5);
        add("端午", 2025, 5, 31,2025,6,2);
        add("国庆", 2025, 10, 1,2025,10,8);
        add("中秋", 2025, 10, 1,2025,10,8);
        workday.add(LocalDate.of(2025, 1, 26));
        workday.add(LocalDate.of(2025, 2, 8));
        workday.add(LocalDate.of(2025, 4, 27));
        workday.add(LocalDate.of(2025, 9, 28));
        workday.add(LocalDate.of(2025, 10, 11));
    }

    private void add(String name, int y1, int m1, int d1, int y2, int m2, int d2) {
        holidays.add(new Holiday(
                name,
                LocalDate.of(y1, m1, d1),
                LocalDate.of(y2, m2, d2)
        ));
    }


    /**
     * 判断是否为休息日
     * @param query
     * @return
     */
    public boolean in(LocalDate query) {
        for (LocalDate localDate : workday) {
            if (query.equals(localDate)) {
                return false;
            }
        }
        for (Holiday holiday : holidays) {
            if (query.equals(holiday.start)) {
                return true;
            }
            if (query.equals(holiday.end)) {
                return true;
            }
            if (query.isAfter(holiday.start) && query.isBefore(holiday.end)) {
                return true;
            }
        }
        if (query.getDayOfWeek().getValue() > 5) {
            return true;
        }
        return false;
    }
}
